﻿
namespace Leetcode.N0965;

public class Solution
{
    public bool IsUnivalTree(TreeNode root)
    {
        return this.IsUnivalTree(root, root.val);
    }

    private bool IsUnivalTree(TreeNode node, int val)
    {
        if (node == null)
        {
            return true;
        }

        if (node.val != val)
        {
            return false;
        }

        return this.IsUnivalTree(node.left, val) && this.IsUnivalTree(node.right, val);

    }
}